<template>
	<view class="goods-item-card">
		<radio :checked="item.goods_state" color="#FF6600" class="card-radio" v-if="showRadio"
			@click="radioClickHandler"></radio>
		<view class="card-image">
			<image class="goods-pic" :src="item.goods_small_logo || defaultPic"></image>
		</view>
		<view class="card-right-box">
			<view class="category"> Illustration </view>
			<view class="heading"> {{item.goods_name}}</view>
			<view class="author">
				<view class="author-price">
					<text>￥{{item.goods_price.split('.')[0]}}</text>
					<text class="author-text">.{{item.goods_price.split('.')[1]}}</text>
				</view>
				<view class="author-right" v-if="showNum">
					<view class="count-box-item" v-if="!discount" @click="countShow">
						<uni-icons type="closeempty" size="16" />
						<text>{{item.goods_count}}</text>
					</view>
					<view class="count-box" v-else>
						<uni-number-box :min="1" :value="item.goods_count" @change="numChangHandler" />
						<view class="count-box-x" @click="countHide">
							<uni-icons type="closeempty" size="20" color="#FFFFFF"></uni-icons>
						</view>
					</view>
				</view>
			</view>

		</view>
	</view>

</template>

<script>
	export default {
		name: "my-goods",
		props: {
			item: {
				type: Object,
				default: {}
			},
			showRadio: {
				type: Boolean,
				// 默认不展示radio组件
				default: false
			},
			showNum: {
				type: Boolean,
				// 默认不展示uni-number-box组件
				default: false
			}

		},
		data() {
			return {
				// /默认的空图片
				defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png',
				discount: false
			};
		},
		methods: {
			// 这个是radio组件的点击事件处理函数
			radioClickHandler() {
				// 调用那边的事件
				this.$emit('radio-change', {
					goods_id: this.item.goods_id,
					goods_state: !this.item.goods_state
				})
			},
			countHide() {
				this.discount = false
			},
			countShow() {
				this.discount = true
			},
			// 商品数量的处理函数
			numChangHandler(val) {
				this.$emit('num-change', {
					goods_id: this.item.goods_id,
					goods_count: val - 0
				})
			}
		}
	}
</script>

<style lang="scss">
	.goods-item-card {
		height: 140px;
		display: flex;
		align-items: center;
		background: white;
		border-radius: 6px;
		margin: 8rpx 16rpx;
		// box-shadow: 15px 15px 30px #bebebe,
		// 	-15px -15px 30px #ffffff;
		box-shadow: 0px 0px 20px #DDDDDD;

		.card-radio {
			margin-left: 10rpx;
			// transform: scale(0.8);
		}

		.card-image {
			position: relative;

			.goods-pic {
				width: 160rpx;
				height: 160rpx;
				border-radius: 16rpx;
				margin-right: 10rpx;
				// position: absolute;
				// top: 50%;
				// left: 50%;
				// transform: translate(-50%, -50%);
			}
		}

		.card-right-box {
			display: flex;
			flex: 1;
			flex-direction: column;

			.category {
				text-transform: uppercase;
				font-weight: 600;
				color: #d4c7ff;
			}

			.heading {
				font-size: 26rpx;
				font-weight: 600;
				margin: 10rpx;
				margin-left: 0;
				overflow: hidden;
				text-overflow: ellipsis;
				/* 将对象作为弹性伸缩盒子模型显示 */
				display: -webkit-box;
				/* 限制在一个块元素显示的文本的行数 */
				-webkit-line-clamp: 3;
				/* 设置或检索伸缩盒对象的子元素的排列方式 */
				-webkit-box-orient: vertical;
			}

			.author {
				width: 100%;
				height: 40px;
				color: #C00000;
				font-weight: 400;
				font-size: 32rpx;
				padding-right: 4rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.author-price .author-text {
					font-size: 14px;
				}

				.count-box-item {
					width: 40px;
					height: 35px;
					line-height: 35px;
					text-align: center;
					color: #222222;
					border-radius: 4px;
					border: 1px solid #e5e5e5;
					margin-right: 5px;
				}

				.count-box {
					display: flex;
					align-items: center;
					justify-content: flex-start;

					.count-box-x {
						width: 30px;
						height: 30px;
						text-align: center;
						line-height: 30px;
						border-radius: 50%;
						margin-right: 5px;
						background-color: #FF6600;
					}
				}
			}
		}

	}
</style>
